<html>
<head><meta charset="utf-8"><title>Advanced cargo features · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advanced.20cargo.20features.html">Advanced cargo features</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="184788966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advanced%20cargo%20features/near/184788966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advanced.20cargo.20features.html#184788966">(Jan 04 2020 at 05:08)</a>:</h4>
<p>In Cargo.toml, is it possible to say that a dependency has a feature only if a feature of my own crate is enabled? Root issue: I have a case where I have a proc-macro crate, and I only want it to emit certain code if a feature in my main crate is turned on/off.</p>



<a name="184788972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advanced%20cargo%20features/near/184788972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advanced.20cargo.20features.html#184788972">(Jan 04 2020 at 05:08)</a>:</h4>
<p>My code is in a workspace, and the main crate depends on the proc-macro crate, then re-exports it.</p>



<a name="184788987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advanced%20cargo%20features/near/184788987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advanced.20cargo.20features.html#184788987">(Jan 04 2020 at 05:09)</a>:</h4>
<p>Or, would my only option be to not have the main crate depend on the proc-macro crate, and enforce that my users set the features on both crates</p>



<a name="184792030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advanced%20cargo%20features/near/184792030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advanced.20cargo.20features.html#184792030">(Jan 04 2020 at 06:53)</a>:</h4>
<p>yes, make a feature in your crate, and then make it have a required "dependency/feature" instead of just a required "feature".</p>
<div class="codehilite"><pre><span></span><span class="k">[dependencies]</span>
<span class="n">my_crate_feature</span> <span class="o">=</span> <span class="k">[&quot;dep_name/dep_feature&quot;]</span>
</pre></div>



<a name="184815851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advanced%20cargo%20features/near/184815851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advanced.20cargo.20features.html#184815851">(Jan 04 2020 at 19:13)</a>:</h4>
<p>That worked. Thank you!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>